package com.yang.designmode.factory.AbstractFactory;

public class AbstractFactory {

    public static void main(String[] args) {
        Car car = new LuxuryEngineCarFactory().createCar();
        Engine engine = new LuxuryEngineCarFactory().createEngine();
        car.run();
        engine.run();

    }
    //抽象工厂
    public static interface AbstractComponentFactory {
        Car createCar();
        Engine createEngine();
    }

    public static class LuxuryEngineCarFactory  implements AbstractComponentFactory {
        @Override
        public Car createCar() {
            return new BydCarFactory().createCar();
        }
        @Override
        public Engine createEngine() {
            return new LuxuryEngineFactory().createEngine();
        }
    }

    public static class LowEngineCarFactory  implements AbstractComponentFactory {
        @Override
        public Car createCar() {
            return new AudiCarFactory().createCar();
        }
        @Override
        public Engine createEngine() {
            return new LowEngineFactory().createEngine();
        }
    }

    //汽车产品族
    public static interface Car {
        void run();
    }

    public static class Byd implements Car {
        @Override
        public void run() {
            System.out.println("比亚迪...");
        }
    }

    public static class Audi implements Car {
        @Override
        public void run() {
            System.out.println("奥迪...");
        }
    }

    public static interface CarFactory {
        Car createCar();
    }


    public static class AudiCarFactory implements CarFactory{
        public Car createCar() {
            return new Audi();
        }
    }
    public static class BydCarFactory implements CarFactory{
        public Car createCar() {
            return new Byd();
        }
    }

    //发动机产品族
    public static interface EngineFactory {
        Engine createEngine();
    }
    public static interface Engine {
        void run();
    }
    public static class LuxuryEngine implements Engine {
        @Override
        public void run() {
            System.out.println(" luxury engine...");
        }

    }
    public static class LowEngine implements Engine {
        @Override
        public void run() {
            System.out.println(" low engine...");
        }

    }

    public static class LuxuryEngineFactory implements EngineFactory{
        public Engine createEngine() {
            return new LuxuryEngine();
        }
    }

    public static class LowEngineFactory implements EngineFactory{
        public Engine createEngine() {
            return new LowEngine();
        }
    }

}
